﻿using System.Collections.Generic;
using Interfaces.Criteria;
using Interfaces.Filters;
using Interfaces.Models;
using Interfaces.Providers;
using Interfaces.Repositories;
using Interfaces.RepositoryModels.ExternalModels.FilterModels;
using Interfaces.Validation;
using Interfaces.Validation.Repositories;
using Microsoft.Practices.Prism.Modularity;
using Microsoft.Practices.Unity;
using SQLRepositories.EconomicRepositories;
using SQLRepositories.FilterRepositories;
using SQLRepositories.NewsRepositories;
using SQLRepositories.UserRoleRepositories;
using SQLRepositories.ValidationRepository;

namespace SQLRepositories
{
    public class SqlRepositoryModule : IModule
    {
        private readonly IUnityContainer _container;

        public SqlRepositoryModule(IUnityContainer container)
        {
            _container = container;
        }

        public void Initialize()
        {
            
            _container.RegisterType<IDBEconomicInformationServiceContext, DBEconomicInformationServiceContext>(new PerThreadLifetimeManager());
            
            #region UserRole
            
            _container.RegisterType<IUserRepository, UserRepository>();
            _container.RegisterType<IRoleRepository, RoleRepository>();
            _container.RegisterType<ISessionRepository, SessionRepository>();

            #endregion

            #region Economic

            _container.RegisterType<ISectorRepository, SectorRepository>();
            _container.RegisterType<IIndustryRepository, IndustryRepository>();
            _container.RegisterType<ICompanyRepository, CompanyRepository>();
            _container.RegisterType<IQuoteisRepository, QuoteisRepository>();

            #endregion

            #region News

            _container.RegisterType<IFeedRepository, FeedRepository>();
            _container.RegisterType<IPersonRepository, PersonRepository>();
            _container.RegisterType<ICategoryRepository, CategoryRepository>();
            _container.RegisterType<INewsDataItemRepository, NewsDataItemRepository>();
            _container.RegisterType<ILinkRepository, LinkRepository>();

            #endregion

            #region Filters

            _container.RegisterType<IFilterRepository<NewsFilterModel>, NewsFilterRepository>();
            _container.RegisterType<IFilterRepository<SectorsFilterModel>, SectorsFilterRepository>();
            _container.RegisterType<IFilterRepository<IndustryFilterModel>, IndustryFilterRepository>();
            _container.RegisterType<IFilterRepository<QuoteisFilterModel>, QuoteisFiltereRepository>();
            _container.RegisterType<IFilterRepository<XchangeRateFilterModel>, XchangeRateFilterRepository>();
            _container.RegisterType<IFilterRepository<CompanyFilterModel>, CompanyFilterRepository>();

            #endregion

            #region Providers

            _container.RegisterType
              <IEconomicDataProvider<IEnumerable<ICompany>, ICompanyFilter, IKeySupportedCriteria>, CompanyRepository>();

            _container.RegisterType
              <IEconomicDataProvider<IEnumerable<IPair>, IPairFilter, IKeySupportedCriteria>, PairRepository>();

            #endregion

            #region Validation

            _container.RegisterType<IUserValidationRepository, UserValidationRepository>(new PerThreadLifetimeManager());
            _container.RegisterType<INewsValidationRepository, NewsValidationRepository>(new PerThreadLifetimeManager());

            #endregion
        }

        public void EnableRepositoryIsDataProvider()
        {
            _container.RegisterType<INewsDataProvider<IFeed, IFilter>, FeedRepository>();
            _container.RegisterType
               <IEconomicDataProvider<IEnumerable<IIndustrySector>, ISectorsFilter, IBaseCriteria>,SectorRepository>();
            _container.RegisterType
                <IEconomicDataProvider<IEnumerable<IIndustry>, IIndustryFilter, IKeySupportedCriteria>, IndustryRepository>();
            _container.RegisterType
                <IEconomicDataProvider<IEnumerable<IQuote>, IQuoteisFilter, IKeySupportedCriteria>, QuoteisRepository>();
            _container.RegisterType
                <IEconomicDataProvider<IEnumerable<IXchangeRate>, IXchangeRateFilter, IKeySupportedCriteria>,XchangeRateRepository>();
        }
    }
}
